import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options


# 打开浏览驱动器
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options = chrome_options)
driver.implicitly_wait(3)

# 将浏览器最大化
driver.maximize_window()

# 获取当前目录的selen.html文件
file_path = os.path.join('file:///', os.getcwd(), "selenium.html")
driver.get(file_path)
#最大化窗口
driver.maximize_window()

driver.find_element_by_xpath('//*[@id="signup"]/form/input[1]').send_keys('rabbit')
driver.find_element_by_xpath('//*[@id="signup"]/form/input[2]').send_keys('love')
opt=driver.find_element_by_xpath('//*[@id="signup"]/form/select')
Select(opt).select_by_visible_text('深圳')

#获取所有的复选框
checkbox_eles = driver.find_elements_by_css_selector(
    'div#signup input[type="checkbox"]'
)

for checkbox in checkbox_eles:
    #判断复选框选中状态
    if not checkbox.is_selected():
        checkbox.click()
sleep(2)

driver.find_element_by_css_selector('div#signup form').submit()

# 显式等待,超时时间10秒，每秒查找一次
success_elem = WebDriverWait(driver, 10, 1).until(
    lambda x: x.find_element_by_xpath('//*[@id="signup"]/p').text == "注册成功")
sleep(2)





